package cn.wolfcode.crm.domain;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class CustomerTraceHistory {
    private Long id;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date traceTime;

    private String traceDetails;

    private SystemDictionaryItem traceType;

    private int traceResult;

    private String remark;

    private Customer customer;

    private Employee inputUser;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date inputTime;

    public static final int TRACERESULT_GOOD   = 3; // 跟进结果为优
    public static final int TRACERESULT_MID   = 2; // 跟进结果为中
    public static final int TRACERESULT_BAD   = 1; // 跟进结果为优

    public String getTraceResultName(){
        if (this.traceResult == TRACERESULT_GOOD){
            return "优";
        }else if(this.traceResult == TRACERESULT_MID){
            return "中";
        }else if (this.traceResult == TRACERESULT_BAD){
            return "差";
        }else {
            return "其他";
        }

    }

    public String getJsonData(){
        Map<String,Object> data = new HashMap<>();
        data.put("id",this.getId());
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String traceTime = simpleDateFormat.format(this.traceTime);
        data.put("traceTime",traceTime);
        data.put("traceDetails",this.getTraceDetails());
        data.put("traceType",this.getTraceType());
        data.put("traceTypeId",this.getTraceType().getId());
        data.put("traceTypeName",this.getTraceType().getTitle());
        data.put("traceResult",this.getTraceResult());
        data.put("traceResultName",this.getTraceResultName());
        data.put("remark",this.getRemark());
        //data.put("customer",this.getCustomer());
        data.put("customerId",this.getCustomer().getId());
        data.put("customerName",this.getCustomer().getName());
        data.put("inputUserName",this.getInputUser().getName());
        data.put("inputUserId",this.getInputUser().getId());
        data.put("inputUser",this.getInputUser());


        String inputTime = simpleDateFormat.format(this.inputTime);
        data.put("inputTime",inputTime);
        return JSON.toJSONString(data);
    }

}